package net.chathu.airgw.packets.chat 
{
	import net.chathu.airgw.Config;
	import net.chathu.airgw.model.User;
	import net.chathu.airgw.packets.gw.serverpackets.EchoPacket;
	import net.chathu.airgw.util.StringUtil;
	/**
	 * ...
	 * @author ze
	 */
	public class IAddsUsers extends ChatPacket
	{
		
		public function IAddsUsers() 
		{
			
		}
		
		override public function execute():void
		{
			var id:int;
			var regName:String;
			var sex:int;
			var regId:int;
			var color:String;
			var disturb:int;
			var age:int;
			var type:int;
			
			var index:int = 3;

			while (index + 2 < data.length) {
				// LEHET, HOGY A LEGUTOLSO USERT NEM ADJA HOZZA!!??
				try {

					//565505|8|d|1|u|4653562|t|36|s|1|b||c|FFA200|a|0|n|Aeon75
					
					id=parseInt(data[index]);
					disturb = parseInt(data[index + 3]);
					regId=parseInt(data[index+5]);
					sex = parseInt(data[index + 9]);
					type = parseInt(data[index + 7]);
					color = data[index + 13];
					age=data[index+15];
					regName = StringUtil.convertFromISO88591(data[index + 17]);
					var isItYou:Boolean = (regName == sessionData.chatData.username);
					var user:User = new User(id, regId, regName, sex, age, color, disturb, type);
					sessionData.chatData.users.add(user,isItYou);
					//itt nem kell konvertalas..
					if (regName == sessionData.chatData.username)
					{
						sessionData.chatData.userId = id;
					}

				}catch(err:Error) {
					trace("ItemsUsers error:" + err.name);
					throw err;
				}
				index += 18;
				//index+=parseInt(data[index+1])*2+2;
			}
		}
		
	}

}